<?php

declare (strict_types = 1);

namespace app\controller\system;

use app\BaseController;
use app\service\system\ResourceService;
use owns\exception\TransException;

/**
 * 文件资源
 */
class Resource extends BaseController
{
    protected $resourceService;

    public function initialize()
    {
        $this->resourceService = make(ResourceService::class);
    }
    /**
     * 文件类型
     */
    public function typeList()
    {
        return $this->success($this->resourceService->typeList());
    }
    /**
     * 列表
     */
    public function list() 
    {
        return $this->success($this->resourceService->list($this->paging()));
    }
    /**
     * 编辑
     */
    public function edit()
    {
        $param = $this->request->post();
        return $this->success($this->resourceService->edit($param));
    }
    /**
     * 删除
     */
    public function delete()
    {
        $param = $this->request->delete();
        $this->validate($param, []);
        return TransException::exec(ResourceService::class, 'delete', $param['id']);
    }
}